package cn.wolfcode.producer._04_consumeway;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * 消费方式生产者
 */
public class ConsumeWayProducer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //1.创建一个生产者对象
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("wolfcode-consumer");
        //2.设置名字服务的地址
        defaultMQProducer.setNamesrvAddr("127.0.0.1:9876");
        //3.启动生产者
        defaultMQProducer.start();
        //4.创建一个消息
        Message message = new Message("06-consumeway-boot", "tagA", "你好，rocketMQ！".getBytes());
        //5.生产者发送消息
        defaultMQProducer.setSendMsgTimeout(10000);
        defaultMQProducer.send(message);
        System.out.println(message.getBody());
        System.out.println(message.getTopic());
        //6.关闭连接
        defaultMQProducer.shutdown();
    }
}
